package servlet.Jamin;

import net.sf.json.JSONObject;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/ForgetPasswordServelt")

public class ForgetPassword extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserServiceImpl us = new UserServiceImpl();
        PrintWriter out = response.getWriter();
        JSONObject json = new JSONObject();
        String s1 = request.getParameter("f_account");
        String s2 = request.getParameter("f_phonenumber");
        int a = us.searchUser(s1, s2);
        if (a == 1) {

            String s3 = request.getParameter("password");
            int b = us.resetPwd(s3, s1);
            if (b != 0) {
               json.put("fp",true);
            } else {
                json.put("fp",false);
            }


        } else {
            json.put("fp", false);
        }

        out.println(json);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
